package flc.ast.fragment;

import android.graphics.Color;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.stark.calculator.mortgage.BaseMortFragment;
import com.stark.calculator.mortgage.model.LoanModel;

import flc.ast.R;
import flc.ast.activity.HouseResultActivity;
import flc.ast.activity.RateTableActivity;
import flc.ast.databinding.FragmentHouseKind1Binding;
import stark.common.basic.view.InputUnitView;
import stark.common.basic.view.TextSwitch;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link HouseKind1Fragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class HouseKind1Fragment extends BaseMortFragment<FragmentHouseKind1Binding> {

    @Override
    protected InputUnitView getFundAmountView() {
        return null;
    }

    @Override
    protected InputUnitView getFundInterestView() {
        return null;
    }

    //贷款金额
    @Override
    protected InputUnitView getCommercialAmountView() {
        return mDataBinding.iuHouseKind1Dkje;
    }

    //贷款方式切换
    @Override
    protected TextSwitch getInterestMethodView() {
        return mDataBinding.tsSwitch;
    }

    //贷款方式-LPR
    @Override
    protected View getLprBasisContainer() {
        return mDataBinding.llHouseKind1LprView;
    }

    //贷款方式-基准利率
    @Override
    protected View getBaseInterestContainer() {
        return mDataBinding.llHouseKind1JzllView;
    }

    //LPR输入
    @Override
    protected InputUnitView getLprView() {
        return mDataBinding.iuHouseKind1Lpr;
    }

    //基点加减
    @Override
    protected TextSwitch getBasisAddSubView() {
        return mDataBinding.tsHouseKind1Switch;
    }

    //基点输入
    @Override
    protected InputUnitView getBasisInputView() {
        return mDataBinding.iuHouseKind1Jd;
    }

    //贷款利率
    @Override
    protected InputUnitView getCommercialInterestView() {
        return mDataBinding.iuHouseKind1Dkll;
    }

    //贷款折扣
    @Override
    protected InputUnitView getInterestDiscountView() {
        return mDataBinding.iuHouseKind1Dkzk;
    }

    //贷款年限
    @Override
    protected InputUnitView getYearView() {
        return mDataBinding.iuHouseKind1Dknx;
    }

    @Override
    protected TextSwitch getLoanMethodView() {
        return null;
    }

    @Override
    protected int onCreate() {
        return R.layout.fragment_house_kind1;
    }

    @Override
    protected void initData() {
        mDataBinding.ivHouseKind1Form.setOnClickListener(this);
        mDataBinding.ivStartCal.setOnClickListener(this);
        mDataBinding.tvHouseKind1Lpr.setOnClickListener(this);
        mDataBinding.tvHouseKind1Jzll.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()){
            case R.id.tvHouseKind1Lpr:
                clearSelection();
                mDataBinding.tvHouseKind1Lpr.setBackgroundResource(R.drawable.daikuanfangshi1);
                mDataBinding.tvHouseKind1Lpr.setTextColor(Color.WHITE);
                mDataBinding.llHouseKind1LprView.setVisibility(View.VISIBLE);
                break;
            case R.id.tvHouseKind1Jzll:
                clearSelection();
                mDataBinding.tvHouseKind1Jzll.setBackgroundResource(R.drawable.daikuanfangshi1);
                mDataBinding.tvHouseKind1Jzll.setTextColor(Color.WHITE);
                mDataBinding.llHouseKind1JzllView.setVisibility(View.VISIBLE);
                break;
            case R.id.ivHouseKind1Form:
                startActivity(RateTableActivity.class);
                break;
            case R.id.ivStartCal:
                calculate();
                break;
        }
    }

    @Override
    protected void goRetActivity(LoanModel loanModel) {
        HouseResultActivity.loanModel=loanModel;
        startActivity(HouseResultActivity.class);
    }

    private void clearSelection(){
        mDataBinding.tvHouseKind1Jzll.setTextColor(Color.parseColor("#553CEB"));
        mDataBinding.tvHouseKind1Jzll.setBackground(null);
        mDataBinding.tvHouseKind1Lpr.setTextColor(Color.parseColor("#553CEB"));
        mDataBinding.tvHouseKind1Lpr.setBackground(null);
        mDataBinding.llHouseKind1JzllView.setVisibility(View.GONE);
        mDataBinding.llHouseKind1LprView.setVisibility(View.GONE);
    }

}